/*
  学习目标：Switch 和 404
*/

import React from 'react';
import { BrowserRouter as Router, NavLink, Route, Switch } from 'react-router-dom';
import './index.css';

export default class App extends React.Component {
  render() {
    return (
      <>
        <Router>
          <div>
            <NavLink activeClassName="xxx" exact to="/home/test">
              首页
            </NavLink>
            <br />
            <NavLink activeClassName="xxx" exact to="/home">
              首页2
            </NavLink>
            <br />
            <NavLink to="/my">我的</NavLink>
            <br />
            <NavLink to="/friend">朋友</NavLink>
            {/* 👍 推荐使用Switch包住所有的Route组件 */}
            {/* Switch 匹配到第一个组件,就停止向下匹配 */}
            {/* 💥Switch不能包非Route组件 */}
            <Switch>
              <Route path="/friend" component={Friend}></Route>
              <Route path="/home" exact component={Home}></Route>
              <Route path="/home" exact component={Home}></Route>
              <Route path="/home" exact component={Home}></Route>
              <Route path="/my" component={MyMusic}></Route>
              {/* 🔔Switch内最后一个Route不写path, 匹配404 */}
              <Route component={NotFound}></Route>
            </Switch>
          </div>
        </Router>
      </>
    );
  }
}

function NotFound(params) {
  return <div>404页面</div>;
}

function Home() {
  return <h1>首页组件</h1>;
}

function MyMusic() {
  return <h1>我的音乐件</h1>;
}

function Friend() {
  return <h1>朋友组件</h1>;
}
